package com.endpoint.swagger2demo.controller;

import com.endpoint.swagger2demo.pojo.Item;
import io.swagger.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(tags="商品信息controller")
@RestController
@RequestMapping("/item")
public class ItemController {
    @ApiOperation(value = "商品添加",notes = "每个参数都必须获取")
    @ApiImplicitParams({
            @ApiImplicitParam(name="title",value="商品标题"),
            @ApiImplicitParam(name="sellPoint",value="卖点"),
            @ApiImplicitParam(name="num",value="库存"),
            @ApiImplicitParam(name="status",value="商品状态"),
            @ApiImplicitParam(name="created",value="创建时间")
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    @PostMapping("addItem")
    public Item addUser(@RequestParam("title") String title,
                        @RequestParam("sellPoint") String sellPoint,
                        @RequestParam("num")int num,
                        @RequestParam("status")int status,
                        @RequestParam("created")@DateTimeFormat(pattern =
                                "yyyy-MM-dd HH:mm:ss") Date created){
        Item item = new Item();
        item.setTitle(title);
        item.setSellPoint(sellPoint);
        item.setNum(num);
        item.setCreated(created);
        item.setStatus(status);
        return item;
    }
}
